package main

import (
	"alarmservice/com"
	"alarmservice/model"
	"alarmservice/proconfig"
	"alarmservice/tracingservice"
	_ "alarmservice/www/routers"

	"github.com/astaxie/beego"
	"github.com/astaxie/beego/validation"
)

func initValidationMsgTpl() {
	validation.MessageTmpls = map[string]string{
		"Required":     "不能为空",
		"Min":          "最小值为 %d",
		"Max":          "最大值为 %d",
		"Range":        "范围必须是 %d 到 %d",
		"MinSize":      "最小长度为 %d",
		"MaxSize":      "最大长度为 %d",
		"Length":       "长度必须为 %d",
		"Alpha":        "必须为字母",
		"Numeric":      "必须为数字",
		"AlphaNumeric": "必须为字母或数字",
		"Match":        "必须匹配 %s",
		"NoMatch":      "必须不能匹配 %s",
		"AlphaDash":    "必须为字母数字或者'-'",
		"Email":        "必须是有效的邮箱地址",
		"IP":           "必须是有效的IP地址",
		"Base64":       "必须是Base64编码",
		"Mobile":       "必须为手机号码",
		"Tel":          "必须为电话号码",
		"Phone":        "必须为手机或电话号码",
		"ZipCode":      "必须为邮政编码",
	}
}

func initTplFunc() {
	beego.AddFuncMap("printStruct", com.PrintStruct)
	beego.AddFuncMap("mkSlice", com.TplMkSlice)
	beego.AddFuncMap("addToMap", com.TplAddToMap)
}

func main() {
	beego.SetLogger("file", `{"filename":"/tmp/logs/alarmservice.log"}`)
	beego.BeeLogger.DelLogger("console")

	initValidationMsgTpl()
	beego.ParseConfig()
	proconfig.InitByRunMode(beego.AppConfig.String("runmode"))
	model.Init()
	tracingservice.Init()
	initTplFunc()

	beego.Run()
}
